<?php
class region_model extends jqxGrid_CI_Model {

    function __construct()
    {
        parent::__construct();
        
    }
    function getCitys(){
        $where=array("Delete"=>Null,"Status"=>"true");
        $query=$this->db
                ->where($where)
                ->get("re_tinhthanh"); 
        return $query->result();
    }
    function getDistricts($city=""){
        $where=array("Delete"=>Null,"Status"=>"true","MaTinhThanh"=>$city);
        $query=$this->db
                ->where($where)
                ->get("re_quanhuyen"); 
        return $query->result();
    }
    function getWard($district=""){
        $where=array("Delete"=>Null,"Status"=>"true","MaQuanHuyen"=>$district);
        $query=$this->db
                ->where($where)
                ->get("re_phuongxa"); 
        return $query->result();
    }
    function binding_city(){
        $strQuery="
            SELECT SQL_CALC_FOUND_ROWS `re_tinhthanh`.*
            FROM `re_tinhthanh`
            ";
        $strWhere="
            WHERE  true
            ";
        $strOrderBy="Order By `ThuTu` ASC ";
        $strGroupBy="";
        $config=array(
            "strQuery"=>$strQuery,
            "strWhere"=>$strWhere,
            "strOrderBy"=>$strOrderBy,
            "strGroupBy"=>$strGroupBy,
            "usingLimit"=>false,
            "fields"=>array(),
            "datefields"=>array()
        );
        $this->init($config);
        return $this->jqxBinding();
    }
    function binding_district($city=""){
        $city=  mysql_escape_string($city);
        $strQuery="
            SELECT SQL_CALC_FOUND_ROWS `re_quanhuyen`.*
            FROM `re_quanhuyen`
            ";
        $strWhere="
            WHERE  MaTinhThanh='$city'
            ";
        $strOrderBy="Order By `ThuTu` ASC ";
        $strGroupBy="";
        $config=array(
            "strQuery"=>$strQuery,
            "strWhere"=>$strWhere,
            "strOrderBy"=>$strOrderBy,
            "strGroupBy"=>$strGroupBy,
            "usingLimit"=>false,
            "fields"=>array(),
            "datefields"=>array()
        );
        $this->init($config);
        return $this->jqxBinding();
    }
    function binding_ward($district=""){
        $district=  mysql_escape_string($district);
        $strQuery="
            SELECT SQL_CALC_FOUND_ROWS `re_phuongxa`.*
            FROM `re_phuongxa`
            ";
        $strWhere="
            WHERE  MaQuanHuyen='$district'
            ";
        $strOrderBy="Order By `ThuTu` ASC ";
        $strGroupBy="";
        $config=array(
            "strQuery"=>$strQuery,
            "strWhere"=>$strWhere,
            "strOrderBy"=>$strOrderBy,
            "strGroupBy"=>$strGroupBy,
            "usingLimit"=>false,
            "fields"=>array(),
            "datefields"=>array()
        );
        $this->init($config);
        return $this->jqxBinding();
    }
}
?>
